require "Common/define"
require "Logic/Config"
require "Common/functions"

EquipListItem = {}
HelperFunc.SetUIEnv(EquipListItem)
local this = EquipListItem;
this.LuaBehaviour = nil;

function EquipListItem.Init()
    local name, packageName = getUIName(PanelNames.EquipListItem);
    panelMgr:ShowUI(name, packageName, this.onCreate, Config.useLocalUI);
end

function EquipListItem.onCreate(obj)
    
end

function EquipListItem.initData(obj, data)
    local name = obj:GetChild("name");
    local refine = obj:GetChild("refine");
    local attack = obj:GetChild("attack");
    local equipItem = obj:GetChild("equipItem");

    local ctrlItem = CtrlManager.GetCtrl(PanelNames.Item);
    if ctrlItem ~= nil then
        ctrlItem.initData(equipItem, data);
    end

    name.text = data["name"]
    if data["curRfLevel"] == 0 then
        refine.text = "";
    else
        refine.text = data["curRfLevel"];
    end
    attack.text = data["power"] or ""
    -- local descrip = obj:GetChild("Txt_Description")
    -- if descrip then
    
    -- end
    --奇异碎片 特殊处理
    if data.itemType == EnumConst.ItemTypeEnum.Fragment then 
        local _btnTitle = ""
        local _touchable = true
        local _conditionStr = ""
        if data["num"] == nil or data.num == 0 then
            _touchable = false
            _conditionStr = data.f_DropDes
            --未获得
            _btnTitle = getLanguage("Fragment_NotGet")
        elseif not string.IsNilOrEmpty(data.partnerId) then
            --"替 换"
            _btnTitle = getLanguage("Fragment_Swap")
        else
            --镶 嵌
            _btnTitle = getLanguage("Fragment_Inlay")
        end

        local Txt_Condition = obj:GetChild("Txt_Condition")
        if Txt_Condition then
            Txt_Condition.text = _conditionStr
        end
        local btn_unreplace = obj:GetChild("btn_unreplace")
        if btn_unreplace then
            btn_unreplace.title = _btnTitle
            --btn_unreplace.enabled = _touchable
            --btn_unreplace.touchable = _touchable
        end
    else
        local btn_unreplace = obj:GetChild("btn_unreplace")
        if btn_unreplace then
            if data["heroName"] then
                btn_unreplace.title = getLanguage("Fragment_Swap")
            else
                btn_unreplace.title = getLanguage("Fragment_Inlay")
            end
            btn_unreplace.enabled = true
            btn_unreplace.touchable = true
        end
    end
end

return EquipListItem;